﻿@model System.Guid
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script src="/Contents/scripts/jquery-1.8.0.min.js" type="text/javascript"></script>
        <script src="/Contents/scripts/functions.js" type="text/javascript"></script>
        <link href="/Contents/css/glassbtn.css" rel="stylesheet" type="text/css" />
        <style type="text/css">
            .left{float:left; width:70px; text-align:right;font-family:微软雅黑;color:#444444;line-height:26px;margin-bottom:12px;}
            .right{float:left;}
            
            .area{border:1px solid #ccc; height:70px; width:350px;text-indent:5px;margin-bottom:12px;}
            .area:hover{border:1px solid #88C5EE; height:70px; width:500px; text-indent:5px;}
            
            .shuru{border:1px solid #ccc; height:23px; width:350px;line-height:23px; text-indent:5px;margin-bottom:12px;}
            .shuru:hover{border:1px solid #88C5EE; height:23px; line-height:23px; text-indent:5px;}
            
            .answer_key{font-family:微软雅黑;width:70px;height:26px;line-height:26px;float:left;}
        </style>
    </head>
    <body style="padding-left:5px;padding-top:5px;">
        <div style="float:left;" >
            <div class="left">题目：</div>
            <div class="right">
                <textarea class="area" id="title" style="width:350px; height:60px;"></textarea>
            </div>
            <div class="left">选项A：</div>
            <div class="right">
                <input type="text" class="shuru" id="answer_a" />
            </div>
            <div class="left">选项B：</div>
            <div class="right">
                <input type="text" class="shuru" id="answer_b" />
            </div>
            <div class="left">选项C：</div>
            <div class="right">
                <input type="text" class="shuru" id="answer_c" />
            </div>
            <div class="left">选项D：</div>
            <div class="right">
                <input type="text" class="shuru" id="answer_d" />
            </div>
            <table style="width:400px;">
                <tr>
                    <div class="left">答案：</div>
                    <div class="right" id="key_div">
                        <div class="answer_key"><input type="checkbox" value="A" id="key_a" /><label for="key_a">&nbsp;A&nbsp;</label></div>
                        <div class="answer_key"><input type="checkbox" value="B" id="key_b" /><label for="key_b">&nbsp;B&nbsp;</label></div>
                        <div class="answer_key"><input type="checkbox" value="C" id="key_c" /><label for="key_c">&nbsp;C&nbsp;</label></div>
                        <div class="answer_key"><input type="checkbox" value="D" id="key_d" /><label for="key_d">&nbsp;D&nbsp;</label></div>
                    </div>
                </tr>
            </table>
            <div class="left">解析：</div>
            <div class="right">
                <textarea class="area" id="analysis" style="width:350px; height:60px;"></textarea>
            </div>
            
        </div> 
        <div style="float:left;">
            <input type="button" class="greenbtn" style="width:70px;margin-left:140px;margin-top:15px;" value="添加" name="add_new_btn" onclick="addChoice()"/>
        </div>
        <div style="float:left;">
            <input type="button" class="greenbtn" style="width:70px;margin-top:15px;margin-left:35px;" value="取消" name="cancel_btn" onclick="fr_all_choice_closeForm()" />
         </div>
        <script type="text/javascript">
            $(document).ready(function () {
                $("#title").focus();
            })
            function fr_all_choice_closeForm() {
                parent.closeShade();
            }
            function addChoice() {
                var title = trim($("#title").val());
                var a = trim($("#answer_a").val());
                var b = trim($("#answer_b").val());
                var c = trim($("#answer_c").val());
                var d = trim($("#answer_d").val());
                var analysis = trim($("#analysis").val());

                if (title.length == 0) {
                    alert("请输入题目!");
                    return;
                }
                if (a.length == 0) {
                    alert("请输入选项 A !");
                    return;
                }
                if (b.length == 0) {
                    alert("请输入选项 B !");
                    return;
                }
                if (c.length == 0) {
                    alert("请输入选项 C !");
                    return;
                }
                if (d.length == 0) {
                    alert("请输入选项 D !");
                    return;
                }

                // 获取答案
                var inputs = document.getElementById("key_div").getElementsByTagName("input");
                var count= 0;
                var keys = "";
                for (var i = 0; i < inputs.length; i++) {
                    if ((inputs[i].type = "checkbox") && (inputs[i].checked == true)) {
                        count++;
                        keys += inputs[i].value + "、";
                    }
                }
                if (count == 0) {
                    alert("请选择正确答案 !");
                    return;
                }
                
                ajaxAddChoice("@Model.ToString()",title, a, b, c, d, keys, analysis);
            }
            function ajaxAddChoice(id,title, a, b, c, d, keys, analysis) {
                $.ajax({
                    type: 'GET',
                    url: '/FrAnalysisChoiceManagement/AddChoice?t=' + Math.random(),
                    data: { id:id,title: title, a: a, b: b, c: c, d: d, key: keys, analysis: analysis },
                    success: function (data) {
                        if (data == "0") {
                            alert("出现未知异常导致添加失败,请重试!");
                        }
                        else if (data == "1") {
                            parent.reloadDG();
                        }
                    }
                });
            }
        </script>
    </body>
</html>
